package net.wanglu.www.zzz.rule;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Properties;

import net.wanglu.www.zzz.service.se.__SentenceElements;
import net.wanglu.www.zzz.service.se.__SentenceExtracter;
import net.wanglu.www.zzz.service.se.nsubj._NSubjTuple;
import net.wanglu.www.zzz.utils.WangluNLPUtils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestSvaMain {

	public static String[] appXmls = {"rule-0.xml","rule-pronoun.xml","rule-runon.xml","rule-sva.xml","service-0.xml","service-sent.xml"};
	public static String test = "propernoun.properties";
	static String RuleName = "PropernounAsSubj";
	static int start = 10, end = 15;

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
        ApplicationContext ctx = new ClassPathXmlApplicationContext(appXmls);
		Rule rule = (Rule) ctx.getBean(RuleName);
		__SentenceExtracter ext = (__SentenceExtracter) ctx.getBean("__SentenceExtracter");
		Properties prop = new Properties();
		InputStream is = TestSvaMain.class.getResourceAsStream(test);
		prop.load(is);
		
		for( int i=start; i<=end; i++) {
			String sentence = prop.getProperty(String.valueOf(i));
			System.out.println(i);
			System.out.println(sentence);
			
			Object preprocessData = WangluNLPUtils.sentencePreprocess(sentence);
			__SentenceElements se = (__SentenceElements) ext.service(preprocessData);

			for( _NSubjTuple nst : se.NSubjTupleList) {
				Object rs = rule.examine(preprocessData, nst);
				if ( rs instanceof Integer && rs == Rule.Inapplicable) {
					System.out.println("Inapplicable");
				} else if ( rs instanceof BadEgg){
					BadEgg egg = (BadEgg) rs;
					System.out.println(egg.getViolatedRule().getRuleName());
					System.out.println("whereiswrong:");
					System.out.println(egg.whereIsWrong.toString());
					System.out.println("whyiswrong:");
					System.out.println(egg.getViolatedRule().whyItsWrong(preprocessData, egg));
					System.out.println("solutions:");
					System.out.println(egg.getViolatedRule().deviseRightSolution(preprocessData, egg));
					System.out.println("-----------------");
				
				} else if ( rs == null) {
					System.out.println("Pass");
				} else {
					System.out.println("What's that?");
					System.out.println(rs);
				}				
			}
			System.out.println("**********************");
		}
	}
}
